/** 
 * AbstractSymbolTable.java
 * @author Lex
 * 2007-8-24 ����06:52:04
 */
package fun.symtable;

import java.util.Iterator;

public abstract class AbstractSymbolTable implements SymbolTable {
	protected String name = "";
	protected SymbolTable parent = null;

	public AbstractSymbolTable(String name) {
		super();
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public SymbolTable getParent() {
		return parent;
	}

	public void setParent(SymbolTable parent) {
		this.parent = parent;
	}

	public String toString() {
	StringBuilder b = new StringBuilder();
	b.append(this.getName()).append('[');
	// parent
	b.append("parent=");
	SymbolTable parent = this.getParent();
	if (null == parent)
	    b.append("null");
	else
	    b.append(parent.getName());
	b.append(',').append(' ');
	// functions
	b.append("functions=[");
	Iterator<FunctionEntry> fun = this.functions();
	while (fun.hasNext()) {
	    b.append(fun.next().getName());
	    if (fun.hasNext())
		b.append(',').append(' ');
	}
	b.append(']');
	// variables;
	b.append(", variables=[");
	Iterator<VariableEntry> var = this.variables();
	while (var.hasNext()) {
	    b.append(var.next().getName());
	    if (var.hasNext())
		b.append(',').append(' ');
	}
	b.append(']').append(' ').append(']');
	return b.toString();
    }
}
